home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / sbzreval.c < prev   
C/C++ Source or Header  |  1995-12-30  |  8KB  |  187 lines

  1. /******************************************************************************
  2. * SBzrEval.c - Bezier surfaces handling routines - evaluation routines.          *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Mar. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * DESCRIPTION:                                                               M
  11. * Evaluates the given tensor product Bezier surface at a given point, by     M
  12. * extracting an isoparamteric curve along u from the surface and evaluating  M
  13. * the curve at parameter v.                                                  M
  14. *                                         M
  15. *        u -->                                 V
  16. *     +----------------------+                             V
  17. *     |P0         Pi-1|                             V
  18. *   V |Pi        P2i-1|    Parametric space orientation - control mesh. V
  19. *    ||                 |                             V
  20. *    v|Pn-i         Pn-1|                             V
  21. *     +----------------------+                             V
  22. *                                                                            *
  23. * PARAMETERS:                                                                M
  24. *   Srf:       Surface to evaluate at the given (u, v) location.             M
  25. *   u, v:      Location where to evaluate the surface.                       M
  26. *                                                                            *
  27. * RETURN VALUE:                                                              M
  28. *   CagdRType *:  A vector holding all the coefficients of all components    M
  29. *                 of curve Crv's point type. If for example the curve's      M
  30. *                 point type is P2, the W, X, and Y will be saved in the     M
  31. *                 first three locations of the returned vector. The first    M
  32. *                 location (index 0) of the returned vector is reserved for  M
  33. *                 the rational coefficient W and XYZ always starts at second M
  34. *                 location of the returned vector (index 1).                 M
  35. *                                                                            *
  36. * KEYWORDS:                                                                  M
  37. *   BzrSrfEvalAtParam, evaluation, Bezier                                    M
  38. *****************************************************************************/
  39. CagdRType *BzrSrfEvalAtParam(CagdSrfStruct *Srf, CagdRType u, CagdRType v)
  40. {
  41.     CagdRType *Pt;
  42.     CagdCrvStruct
  43.     *IsoCrv = BzrSrfCrvFromSrf(Srf, u, CAGD_CONST_U_DIR);
  44.  
  45.     Pt = BzrCrvEvalAtParam(IsoCrv, v);
  46.  
  47.     CagdCrvFree(IsoCrv);
  48.  
  49.     return Pt;
  50. }
  51.  
  52. /*****************************************************************************
  53. * DESCRIPTION:                                                               M
  54. * Extracts an isoparametric curve out of the given tensor product Bezier     M
  55. * surface in direction Dir at the parameter value of t.                      M
  56. *   Operations should prefer the CONST_U_DIR, in which the extraction is     M
  57. * somewhat faster if that is possible.                         M
  58. *                                                                            *
  59. * PARAMETERS:                                                                M
  60. *   Srf:       To extract an isoparametric ocurve from.                      M
  61. *   t:         Parameter value of extracted isoparametric curve.             M
  62. *   dir:       Direction of the isocurve on the surface. Either U or V.      M
  63. *                                                                            *
  64. * RETURN VALUE:                                                              M
  65. *   CagdCrvStruct *:  An isoparametric curve of Srf. This curve inherits the M
  66. *              order and continuity of surface Srf in direction Dir.  M
  67. *                                                                            *
  68. * KEYWORDS:                                                                  M
  69. *   BzrSrfCrvFromSrf, isoparametric curves, curve from surface               M
  70. *****************************************************************************/
  71. CagdCrvStruct *BzrSrfCrvFromSrf(CagdSrfStruct *Srf,
  72.                 CagdRType t,
  73.                 CagdSrfDirType Dir)
  74. {
  75.     CagdCrvStruct
  76.     *Crv = NULL;
  77.     CagdBType
  78.     IsNotRational = !CAGD_IS_RATIONAL_SRF(Srf);
  79.     int i, j, CrvOrder, VecLen,
  80.     MaxCoord = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  81.     CagdRType *CrvP, *SrfP;
  82.  
  83.     switch (Dir) {
  84.     case CAGD_CONST_U_DIR:
  85.         Crv = BzrCrvNew(CrvOrder = Srf -> VLength, Srf -> PType);
  86.         VecLen = Srf -> ULength;
  87.  
  88.         for (i = IsNotRational; i <= MaxCoord; i++) {
  89.         CrvP = Crv -> Points[i];
  90.         SrfP = Srf -> Points[i];
  91.         for (j = 0; j < CrvOrder; j++) {
  92.             *CrvP++ = BzrCrvEvalVecAtParam(SrfP, CAGD_NEXT_U(Srf),
  93.                                 VecLen, t);
  94.             SrfP += CAGD_NEXT_V(Srf);
  95.         }
  96.         }
  97.         break;
  98.     case CAGD_CONST_V_DIR:
  99.         Crv = BzrCrvNew(CrvOrder = Srf -> ULength, Srf -> PType);
  100.         VecLen = Srf -> VLength;
  101.  
  102.         for (i = IsNotRational; i <= MaxCoord; i++) {
  103.         CrvP = Crv -> Points[i];
  104.         SrfP = Srf -> Points[i];
  105.         for (j = 0; j < CrvOrder; j++) {
  106.             *CrvP++ = BzrCrvEvalVecAtParam(SrfP, CAGD_NEXT_V(Srf),
  107.                                 VecLen, t);
  108.             SrfP += CAGD_NEXT_U(Srf);
  109.         }
  110.         }
  111.         break;
  112.     default:
  113.         CAGD_FATAL_ERROR(CAGD_ERR_DIR_NOT_CONST_UV);
  114.         break;
  115.     }
  116.     return Crv;
  117. }
  118.  
  119. /*****************************************************************************
  120. * DESCRIPTION:                                                               M
  121. * Extracts a curve from the mesh of a tensor product Bezier surface Srf in   M
  122. * direction Dir at index Index.                                              M
  123. *                                                                            *
  124. * PARAMETERS:                                                                M
  125. *   Srf:       To extract a curve from.                               M
  126. *   Index:     Index along the mesh of Srf to extract the curve from.        M
  127. *   Dir:       Direction of extracted curve. Either U or V.             M
  128. *                                                                            *
  129. * RETURN VALUE:                                                              M
  130. *   CagdCrvStruct *:   A curve from Srf. This curve inherit the order and    M
  131. *                      continuity of surface Srf in direction Dir. However,  M
  132. *                      thiscurve is not on surface Srf, in general.          M
  133. *                                                                            *
  134. * KEYWORDS:                                                                  M
  135. *   BzrSrfCrvFromMesh, isoparametric curves, curve from mesh                 M
  136. *****************************************************************************/
  137. CagdCrvStruct *BzrSrfCrvFromMesh(CagdSrfStruct *Srf,
  138.                  int Index,
  139.                  CagdSrfDirType Dir)
  140. {
  141.     CagdCrvStruct
  142.     *Crv = NULL;
  143.     CagdBType
  144.     IsNotRational = !CAGD_IS_RATIONAL_SRF(Srf);
  145.     int i, j, CrvOrder,
  146.     MaxCoord = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  147.     CagdRType *CrvP, *SrfP;
  148.  
  149.     switch (Dir) {
  150.     case CAGD_CONST_U_DIR:
  151.         if (Index + 1 > Srf -> ULength)
  152.         CAGD_FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  153.  
  154.         Crv = BzrCrvNew(CrvOrder = Srf -> VLength, Srf -> PType);
  155.  
  156.         for (i = IsNotRational; i <= MaxCoord; i++) {
  157.         CrvP = Crv -> Points[i];
  158.         SrfP = Srf -> Points[i] + Index * CAGD_NEXT_U(Srf);
  159.         for (j = 0; j < CrvOrder; j++) {
  160.             *CrvP++ = *SrfP;
  161.             SrfP += CAGD_NEXT_V(Srf);
  162.         }
  163.         }
  164.         break;
  165.     case CAGD_CONST_V_DIR:
  166.         if (Index + 1 > Srf -> VLength)
  167.         CAGD_FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  168.  
  169.         Crv = BzrCrvNew(CrvOrder = Srf -> ULength, Srf -> PType);
  170.  
  171.         for (i = IsNotRational; i <= MaxCoord; i++) {
  172.         CrvP = Crv -> Points[i];
  173.         SrfP = Srf -> Points[i] + Index * CAGD_NEXT_V(Srf);
  174.         for (j = 0; j < CrvOrder; j++) {
  175.             *CrvP++ = *SrfP;
  176.             SrfP += CAGD_NEXT_U(Srf);
  177.         }
  178.         }
  179.         break;
  180.     default:
  181.         CAGD_FATAL_ERROR(CAGD_ERR_DIR_NOT_CONST_UV);
  182.         break;
  183.     }
  184.     return Crv;
  185. }
  186.  
  187.